package sequences;

import java.io.BufferedReader;
import java.io.DataInputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Queue;



public class SequenceFromFile implements CharSequence {

	private Queue<Character> sequence;
/**
 * Upon creation, takes in a fileName and fills a priority queue with characters
 * 
 * @param fileName
 */
	public SequenceFromFile(String fileName)
	{
		try {
			File file = new File(fileName);
			if (!file.exists()) {
				System.out.println("Error: Unable to train model... Training file not found.");
			} else {

				FileInputStream fstream = new FileInputStream(file);
				DataInputStream in = new DataInputStream(fstream);
				BufferedReader br = new BufferedReader(new InputStreamReader(in));
				
				String strLine;


				while ((strLine = br.readLine()) != null) {


					for (int i = 0; i < strLine.length();i++) {

						sequence.add(strLine.charAt(i));
					}
				}
				in.close();

			}
		} 
		catch (IOException ex) {
			System.out.println("Error: Unable to access training file... \n" + ex.getMessage());
		}
	}


	public char nextChar() {
		// TODO Auto-generated method stub
		return this.sequence.remove();
	}

}
